#include <sys_config.h>
#include <types.h>
#include <basic_types.h>
#include <mediatypes.h>
#include <api/libc/printf.h>
#include <api/libc/string.h>
#include <osal/osal.h>

#include <api/libosd/osd_lib.h>

#include "osdobjs_def.h"

#include "string.id"
#include "images.id"
#include "osd_config.h"

#include "win_com_menu_define.h"
#include "win_com.h"
#include "menus_root.h"

#include "win_com_popup.h"//ChengYu@20131108, pop up OK/NO dialog when change resolution

#ifdef HDMI_CERTIFICATION_UI
#include <bus/hdmi/m36/hdmi_dev.h>
#endif

#ifdef HDMI_DEEP_COLOR
#include "win_com_popup.h"
#endif

/*******************************************************************************
*	Objects definition
*******************************************************************************/
extern CONTAINER win_av_con;

extern CONTAINER av_item_con1;
extern CONTAINER av_item_con2;
extern CONTAINER av_item_con3;
extern CONTAINER av_item_con4;
extern CONTAINER av_item_con5;
extern CONTAINER av_item_con6;
#ifdef HDTV_SUPPORT
extern CONTAINER av_item_con7;
extern CONTAINER av_item_con8;
#endif
#if (SUPPORT_DUAL_OUTPUT_ONOFF)
extern CONTAINER av_item_con9;
#endif
#ifdef HDMI_DEEP_COLOR
extern CONTAINER av_item_con10; //deep color
#endif

extern TEXT_FIELD av_item_txtname1;
extern TEXT_FIELD av_item_txtname2;
extern TEXT_FIELD av_item_txtname3;
extern TEXT_FIELD av_item_txtname4;
extern TEXT_FIELD av_item_txtname5;
extern TEXT_FIELD av_item_txtname6;
#ifdef HDTV_SUPPORT
extern TEXT_FIELD av_item_txtname7;
extern TEXT_FIELD av_item_txtname8;
#endif
#if (SUPPORT_DUAL_OUTPUT_ONOFF)
extern TEXT_FIELD av_item_txtname9;
#endif
#ifdef HDMI_DEEP_COLOR
extern TEXT_FIELD av_item_txtname10; //deep color
#endif

extern MULTISEL av_item_txtset1;
extern MULTISEL av_item_txtset2;
extern MULTISEL av_item_txtset3;
extern MULTISEL av_item_txtset4;
extern MULTISEL av_item_txtset5;
extern MULTISEL av_item_txtset6;
#ifdef HDTV_SUPPORT
extern MULTISEL av_item_txtset7;
extern MULTISEL av_item_txtset8;
#endif
#if (SUPPORT_DUAL_OUTPUT_ONOFF)
extern MULTISEL av_item_txtset9;
#endif
#ifdef HDMI_DEEP_COLOR
extern MULTISEL av_item_txtset10; //deep color
#endif

extern TEXT_FIELD av_item_line1;
extern TEXT_FIELD av_item_line2;
extern TEXT_FIELD av_item_line3;
extern TEXT_FIELD av_item_line4;
extern TEXT_FIELD av_item_line5;
extern TEXT_FIELD av_item_line6;
#ifdef HDTV_SUPPORT
extern TEXT_FIELD av_item_line7;
extern TEXT_FIELD av_item_line8;
#endif
#if (SUPPORT_DUAL_OUTPUT_ONOFF)
extern TEXT_FIELD av_item_line9;
#endif
#ifdef HDMI_DEEP_COLOR
extern TEXT_FIELD av_item_line10; //deep color
#endif

static VACTION av_item_sel_keymap(POBJECT_HEAD pObj, UINT32 key);
static PRESULT av_item_sel_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2);

static VACTION av_item_con_keymap(POBJECT_HEAD pObj, UINT32 key);
static PRESULT av_item_con_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2);

static VACTION av_con_keymap(POBJECT_HEAD pObj, UINT32 key);
static PRESULT av_con_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2);


#define WIN_SH_IDX	  WSTL_WIN_BODYRIGHT_01_HD

#define CON_SH_IDX   WSTL_BUTTON_01_HD
#define CON_HL_IDX   WSTL_BUTTON_05_HD
#define CON_SL_IDX   WSTL_BUTTON_01_HD
#define CON_GRY_IDX  WSTL_BUTTON_07_HD

#define TXT_SH_IDX   WSTL_BUTTON_01_FG_HD
#define TXT_HL_IDX   WSTL_BUTTON_02_FG_HD
#define TXT_SL_IDX   WSTL_BUTTON_01_FG_HD
#define TXT_GRY_IDX  WSTL_BUTTON_07_HD

#define SEL_SH_IDX   WSTL_BUTTON_01_FG_HD
#define SEL_HL_IDX   WSTL_BUTTON_04_HD
#define SEL_SL_IDX   WSTL_BUTTON_01_FG_HD
#define SEL_GRY_IDX  WSTL_BUTTON_07_HD

#define TXT_L_OF  	TXTN_L_OF
#define TXT_W  		TXTN_W
#define TXT_H		TXTN_H
#define TXT_T_OF	TXTN_T_OF

#define SEL_L_OF 	TXTS_L_OF
#define SEL_W  		TXTS_W
#define SEL_H		TXTS_H
#define SEL_T_OF	TXTS_T_OF

enum
{
    TVMODE_ID = 1,
    TVASPECT_ID,
    VIDEOOUT_ID,
    VCR_ID,
    RFSYSTEM_ID,
    RFCHAN_ID,
#ifdef HDTV_SUPPORT
    HDMIOUT_ID,
    AUDIOOUT_ID,
#endif
#if (SUPPORT_DUAL_OUTPUT_ONOFF)
    DUALOUT_ID,
#endif
#ifdef HDMI_DEEP_COLOR
    DEEPCOLOR_ID,
#endif
    MAX_ID
};

#define LDEF_CON(root, varCon,nxtObj,ID,IDl,IDr,IDu,IDd,l,t,w,h,conobj,focusID)		\
    DEF_CONTAINER(varCon,root,nxtObj,C_ATTR_ACTIVE,0, \
    ID,IDl,IDr,IDu,IDd, l,t,w,h, CON_SH_IDX,CON_HL_IDX,CON_SL_IDX,CON_GRY_IDX,   \
    av_item_con_keymap,av_item_con_callback,  \
    conobj, focusID,1)


#define LDEF_TXT(root,varTxt,nxtObj,l,t,w,h,resID)		\
    DEF_TEXTFIELD(varTxt,root,nxtObj,C_ATTR_ACTIVE,0, \
    0,0,0,0,0, l,t,w,h, TXT_SH_IDX,TXT_HL_IDX,TXT_SL_IDX,TXT_GRY_IDX,   \
    NULL,NULL,  \
    C_ALIGN_LEFT | C_ALIGN_VCENTER, 0,0,resID,NULL)

#define LDEF_MSEL(root, varNum, nxtObj, ID, l, t, w, h,style,cur,cnt,ptabl)	\
    DEF_MULTISEL(varNum,root,nxtObj,C_ATTR_ACTIVE,0, \
    ID,ID,ID,ID,ID, l,t,w,h, SEL_SH_IDX,SEL_HL_IDX,SEL_SL_IDX,SEL_GRY_IDX,   \
    av_item_sel_keymap,av_item_sel_callback,  \
    C_ALIGN_CENTER | C_ALIGN_VCENTER, 20,0,style,ptabl,cur,cnt)

#define LDEF_MENU_ITEM(root,varCon,nxtObj,varTxt,varNum,varLine,ID,IDu,IDd,l,t,w,h,\
						resID,style,cur,cnt,ptbl) \
    LDEF_CON(&root,varCon,nxtObj,ID,ID,ID,IDu,IDd,l,t,w,h,&varTxt,ID)   \
    LDEF_TXT(&varCon,varTxt,&varNum,l + TXT_L_OF,t + TXT_T_OF,TXT_W,TXT_H,resID)    \
    LDEF_MSEL(&varCon,varNum,NULL/*&varLine*/   ,ID, l + SEL_L_OF ,t + SEL_T_OF,SEL_W,SEL_H,style,cur,cnt,ptbl)\
	LDEF_LINE(&varCon,varLine,NULL,1,1,1,1,1,l + LINE_L_OF, t + LINE_T_OF,LINE_W,LINE_H,0,0)

#define LDEF_WIN(varCon,nxtObj,l,t,w,h,focusID)		\
    DEF_CONTAINER(varCon,NULL,NULL,C_ATTR_ACTIVE,0, \
    0,0,0,0,0, l,t,w,h, WIN_SH_IDX,WIN_SH_IDX,WIN_SH_IDX,WIN_SH_IDX,   \
    av_con_keymap,av_con_callback,  \
    nxtObj, focusID,0)

extern UINT16 video_output_ids[];
UINT16 video_vcr_loopthrough_ids[];
extern UINT32 rf_ch_range[][3];
extern UINT8 *format_setting[];
extern UINT8 *audio_setting[];
extern UINT8 *deepcolor_setting[];

#ifndef HDTV_SUPPORT
LDEF_MENU_ITEM(win_av_con,av_item_con1, &av_item_con2,av_item_txtname1,av_item_txtset1,av_item_line1,1,6,2,	\
				CON_L, CON_T + (CON_H + CON_GAP)*0,CON_W,CON_H,	RS_SYSTEM_TV_DISPLAY_MODE,\
				STRING_PROC,0,6,NULL)
				
LDEF_MENU_ITEM(win_av_con,av_item_con2, &av_item_con3,av_item_txtname2,av_item_txtset2,av_item_line2,2,1,3,	\
				CON_L, CON_T + (CON_H + CON_GAP)*1,CON_W,CON_H,	RS_SYSTEM_TV_ASPECT_MODE,\
				STRING_PROC,0,4,NULL)

LDEF_MENU_ITEM(win_av_con,av_item_con3, &av_item_con4,av_item_txtname3,av_item_txtset3,av_item_line3,3,2,4,	\
				CON_L, CON_T + (CON_H + CON_GAP)*2,CON_W,CON_H,	RS_SYSTEM_TV_VIDEO_OUTPUT,\
				STRING_ID,0,3,video_output_ids)


LDEF_MENU_ITEM(win_av_con,av_item_con4, &av_item_con5,av_item_txtname4,av_item_txtset4,av_item_line4,4,3,5,	\
				CON_L, CON_T + (CON_H + CON_GAP)*3,CON_W,CON_H,	RS_VCRLOOPTHROUGH,\
				STRING_ID,0,2,video_vcr_loopthrough_ids)

LDEF_MENU_ITEM(win_av_con,av_item_con5, &av_item_con6,av_item_txtname5,av_item_txtset5,av_item_line5,5,4,6,	\
				CON_L, CON_T + (CON_H + CON_GAP)*4,CON_W,CON_H,	RS_SYSTEM_RF_SYSTEM,\
				STRING_PROC,0,4,NULL)
				
LDEF_MENU_ITEM(win_av_con,av_item_con6, NULL,av_item_txtname6,av_item_txtset6,av_item_line6,6,5,1,	\
				CON_L, CON_T + (CON_H + CON_GAP)*5,CON_W,CON_H,	RS_SYSTEM_RF_CHANNEL,\
				STRING_NUMBER,0,0,rf_ch_range[0])
#else
#ifdef SD_PVR    
LDEF_MENU_ITEM(win_av_con,av_item_con1, &av_item_con2,av_item_txtname1,av_item_txtset1,av_item_line1,1,MAX_ID-1,2,	\
				CON_L, CON_T + (CON_H + CON_GAP)*0,CON_W,CON_H,	RS_SYSTEM_TV_VIDEO_RESOLUTION,\
				STRING_PROC,0,1,NULL)
#else
LDEF_MENU_ITEM(win_av_con,av_item_con1, &av_item_con2,av_item_txtname1,av_item_txtset1,av_item_line1,1,MAX_ID-1,2,	\
				CON_L, CON_T + (CON_H + CON_GAP)*0,CON_W,CON_H,	RS_SYSTEM_TV_VIDEO_RESOLUTION,\
				STRING_PROC,0,10,NULL)
#endif
				
LDEF_MENU_ITEM(win_av_con,av_item_con2, &av_item_con3,av_item_txtname2,av_item_txtset2,av_item_line2,2,1,3,	\
				CON_L, CON_T + (CON_H + CON_GAP)*1,CON_W,CON_H,	RS_SYSTEM_TV_ASPECT_MODE,\
				STRING_PROC,0,4,NULL)

LDEF_MENU_ITEM(win_av_con,av_item_con3, &av_item_con4,av_item_txtname3,av_item_txtset3,av_item_line3,3,2,4,	\
				CON_L, CON_T + (CON_H + CON_GAP)*2,CON_W,CON_H,	RS_SYSTEM_TV_VIDEO_OUTPUT,\
				STRING_PROC,0,2,NULL)


LDEF_MENU_ITEM(win_av_con,av_item_con4, &av_item_con5,av_item_txtname4,av_item_txtset4,av_item_line4,4,3,5,	\
				CON_L, CON_T + (CON_H + CON_GAP)*3,CON_W,CON_H,	RS_VCRLOOPTHROUGH,\
				STRING_ID,0,2,video_vcr_loopthrough_ids)

LDEF_MENU_ITEM(win_av_con,av_item_con5, &av_item_con6,av_item_txtname5,av_item_txtset5,av_item_line5,5,4,6,	\
				CON_L, CON_T + (CON_H + CON_GAP)*4,CON_W,CON_H,	RS_SYSTEM_RF_SYSTEM,\
				STRING_PROC,0,4,NULL)
				
#if (!SUPPORT_DUAL_OUTPUT_ONOFF)
LDEF_MENU_ITEM(win_av_con,av_item_con6, &av_item_con7,av_item_txtname6,av_item_txtset6,av_item_line6,6,5,7,	\
				CON_L, CON_T + (CON_H + CON_GAP)*5,CON_W,CON_H,	RS_SYSTEM_RF_CHANNEL,\
				STRING_NUMBER,0,0,rf_ch_range[0])

LDEF_MENU_ITEM(win_av_con,av_item_con7, &av_item_con8,av_item_txtname7,av_item_txtset7,av_item_line7,7,6,8,	\
				CON_L, CON_T + (CON_H + CON_GAP)*6,CON_W,CON_H,	RS_SYSTEM_TV_HDMI_VIDEO_OUT,\
				STRING_ANSI,0,5,format_setting)

#ifndef HDMI_DEEP_COLOR
LDEF_MENU_ITEM(win_av_con,av_item_con8, NULL,av_item_txtname8,av_item_txtset8,av_item_line8,8,7,1,	\
				CON_L, CON_T + (CON_H + CON_GAP)*7,CON_W,CON_H,	RS_SYSTEM_TV_AUDIO_OUT,\
				STRING_ANSI,0,2,audio_setting)
#else
LDEF_MENU_ITEM(win_av_con,av_item_con8, &av_item_con10,av_item_txtname8,av_item_txtset8,av_item_line8,8,7,9,	\
				CON_L, CON_T + (CON_H + CON_GAP)*7,CON_W,CON_H,	RS_SYSTEM_TV_AUDIO_OUT,\
				STRING_ANSI,0,2,audio_setting)

LDEF_MENU_ITEM(win_av_con,av_item_con10, NULL,av_item_txtname10,av_item_txtset10,av_item_line10,9,8,1,	\
				CON_L, CON_T + (CON_H + CON_GAP)*8,CON_W,CON_H,	RS_HDMI_DEEP_COLOR,\
				STRING_ANSI,0,3,deepcolor_setting)
				
#endif

#else
LDEF_MENU_ITEM(win_av_con,av_item_con6, &av_item_con7,av_item_txtname6,av_item_txtset6,av_item_line6,6,5,7,	\
				CON_L, CON_T + (CON_H + CON_GAP)*5,CON_W,CON_H,	RS_SYSTEM_RF_CHANNEL,\
				STRING_NUMBER,0,0,rf_ch_range[0])

LDEF_MENU_ITEM(win_av_con,av_item_con7, &av_item_con8,av_item_txtname7,av_item_txtset7,av_item_line7,7,6,8,	\
				CON_L, CON_T + (CON_H + CON_GAP)*6,CON_W,CON_H,	RS_SYSTEM_TV_HDMI_VIDEO_OUT,\
				STRING_ANSI,0,5,format_setting)

LDEF_MENU_ITEM(win_av_con,av_item_con8, &av_item_con9,av_item_txtname8,av_item_txtset8,av_item_line8,8,7,9,	\
				CON_L, CON_T + (CON_H + CON_GAP)*7,CON_W,CON_H,	RS_SYSTEM_TV_AUDIO_OUT,\
				STRING_ANSI,0,2,audio_setting)

static UINT16 str_off_on[] = 
{
	RS_COMMON_OFF,
	RS_COMMON_ON,
};
#ifndef HDMI_DEEP_COLOR
LDEF_MENU_ITEM(win_av_con,av_item_con9, NULL,av_item_txtname9,av_item_txtset9,av_item_line9,9,8,1,	\
				CON_L, CON_T + (CON_H + CON_GAP)*9,CON_W,CON_H,	RS_SYSTEM_TV_DUAL_OUTPUT,\
				STRING_ID,0,2,str_off_on)
#else
LDEF_MENU_ITEM(win_av_con,av_item_con9, &av_item_con10,av_item_txtname9,av_item_txtset9,av_item_line9,9,8,10,	\
				CON_L, CON_T + (CON_H + CON_GAP)*9,CON_W,CON_H,	RS_SYSTEM_TV_DUAL_OUTPUT,\
				STRING_ID,0,2,str_off_on)


LDEF_MENU_ITEM(win_av_con,av_item_con10, NULL,av_item_txtname10,av_item_txtset10,av_item_line10,10,9,1,	\
				CON_L, CON_T + (CON_H + CON_GAP)*10,CON_W,CON_H,	RS_HDMI_DEEP_COLOR,\
				STRING_ID,0,3,deepcolor_setting)
#endif
#endif

#endif

LDEF_WIN(win_av_con,&av_item_con1,W_L, W_T, W_W, W_H, 1)


/*******************************************************************************
*	Local functions & variables define
*******************************************************************************/

CONTAINER* av_items[] =
{
	&av_item_con1,
	&av_item_con2,
	&av_item_con3,
	&av_item_con4,
	&av_item_con5,
	&av_item_con6,
#ifdef HDTV_SUPPORT
	&av_item_con7,
	&av_item_con8,
#endif
#if (SUPPORT_DUAL_OUTPUT_ONOFF)
	&av_item_con9,
#endif
#ifdef HDMI_DEEP_COLOR
    &av_item_con10,
#endif
};


MULTISEL* av_item_set[] =
{
	&av_item_txtset1,
	&av_item_txtset2,
	&av_item_txtset3,
	&av_item_txtset4,
	&av_item_txtset5,
	&av_item_txtset6,
#ifdef HDTV_SUPPORT
	&av_item_txtset7,
	&av_item_txtset8,
#endif
#if (SUPPORT_DUAL_OUTPUT_ONOFF)
	&av_item_txtset9,
#endif
#ifdef HDMI_DEEP_COLOR
    &av_item_txtset10,
#endif
};

#ifdef HDMI_TV_TEST // for hdmi tv test, open all resolution
char *tv_mode[] = 
{
	"By Source",
	"By Native TV",
	"480i",
	"480p",
	"576i",
	"576p",
#ifndef SD_PVR	
	"720p_50",
	"720p_60",	
	"1080i_25",
	"1080i_30",	
#ifdef HDMI_1080P_SUPPORT
	"1080p_50",
	"1080p_60",
#ifndef HDMI_CERTIFICATION_UI		
	"1080p_25",
	"1080p_30",
//	"1080p_24",
#endif	
#endif
#endif
};

UINT8 tv_mode_set[] = 
{
	TV_MODE_AUTO,
	TV_MODE_BY_EDID,
	TV_MODE_NTSC358,
	TV_MODE_480P,
	TV_MODE_PAL,
	TV_MODE_576P,
#ifndef SD_PVR	
	TV_MODE_720P_50,
	TV_MODE_720P_60,
	TV_MODE_1080I_25,
	TV_MODE_1080I_30,	
#ifdef HDMI_1080P_SUPPORT
	TV_MODE_1080P_50,
	TV_MODE_1080P_60,
#ifndef HDMI_CERTIFICATION_UI		
	TV_MODE_1080P_25,
	TV_MODE_1080P_30,
	TV_MODE_1080P_24,
#endif	
#endif
#endif
};

char *tv_mode_for_dvi[] = 
{
	"By Source",
	"By Native TV",
	//"480i",
	"480p",
	//"576i",
	"576p",
#ifndef SD_PVR	
	"720p_50",
	"720p_60",	
	"1080i_25",
	"1080i_30",	
#ifdef HDMI_1080P_SUPPORT
	"1080p_50",
	"1080p_60",
#ifndef HDMI_CERTIFICATION_UI	
	"1080p_25",
	"1080p_30",
//	"1080p_24",
#endif	
#endif
#endif
};

UINT8 tv_mode_set_for_dvi[] = 
{
	TV_MODE_AUTO,
	TV_MODE_BY_EDID,
	TV_MODE_480P,
	TV_MODE_576P,
#ifndef SD_PVR		
	TV_MODE_720P_50,
	TV_MODE_720P_60,
	TV_MODE_1080I_25,
	TV_MODE_1080I_30,	
#ifdef HDMI_1080P_SUPPORT
	TV_MODE_1080P_50,
	TV_MODE_1080P_60,
	TV_MODE_1080P_25,
	TV_MODE_1080P_30,
	TV_MODE_1080P_24,
#endif
#endif
};

char* tv_mode_sd[] = 
{
	"By Source",
	"480i",
	"576i",
};

UINT8 tv_mode_set_sd[] = 
{
	TV_MODE_AUTO,
	TV_MODE_NTSC358,
	TV_MODE_PAL,
};
#else
char* tv_mode[] = 
{
	//"By Source",
	//"By Native TV",
	"480i",
	//"480p",
	"576i",
	//"576p",
	//"720p",//"720p_50",
	//"720p_60",	
	//"1080i",//"1080i_25",
	//"1080i_30",	
};

UINT8 tv_mode_set[] = 
{
	//TV_MODE_AUTO,
	//TV_MODE_BY_EDID,
	TV_MODE_NTSC358,
	//TV_MODE_480P,
	TV_MODE_PAL,
	//TV_MODE_576P,
	//TV_MODE_720P_50,
	//TV_MODE_720P_60,
	//TV_MODE_1080I_25,
	//TV_MODE_1080I_30,	
};

char* tv_mode_sd[] = 
{
	//"By Source",
	"480i",
	"576i",
};

UINT8 tv_mode_set_sd[] = 
{
	//TV_MODE_AUTO,
	TV_MODE_NTSC358,
	TV_MODE_PAL,
};
#endif

//******************************//
UINT8 tv_mode_pal[]=
{
	TV_MODE_PAL,
	TV_MODE_576P,
	TV_MODE_720P_50, 
	TV_MODE_1080I_25,
	TV_MODE_1080P_25,
	TV_MODE_1080P_50,
	TV_MODE_1080P_24,
};

UINT8 tv_mode_ntsc[]=
{
	TV_MODE_NTSC358,
    TV_MODE_480P,
	TV_MODE_720P_60,
	TV_MODE_1080I_30,
	TV_MODE_1080P_30,
	TV_MODE_1080P_60,
};

UINT8 tv_mode_pal_ntsc[]=
{
	TV_MODE_AUTO,
	TV_MODE_BY_EDID,
	TV_MODE_NTSC358,
	TV_MODE_480P,
	TV_MODE_PAL,
	TV_MODE_576P,
	
	TV_MODE_720P_50,
	TV_MODE_720P_60,
	TV_MODE_1080I_25,
	TV_MODE_1080I_30,	

	
	TV_MODE_1080P_50,
	TV_MODE_1080P_60,
		
	TV_MODE_1080P_25,
	TV_MODE_1080P_30,
	TV_MODE_1080P_24,
};
//*********************//
#define TV_MODE_NCNT	ARRAY_SIZE(tv_mode)
#ifdef HDMI_CERTIFICATION_UI
#define TV_MODE_DVI_NCNT	ARRAY_SIZE(tv_mode_for_dvi)
#endif
#define TV_MODE_SD_NCNT	ARRAY_SIZE(tv_mode_set_sd)

#ifndef HDMI_CERTIFICATION_UI
UINT8 *format_setting[] = 
{
	"Auto",
	"RGB-Normal",
	"RGB-Expand",
	"YCbCr 4:4:4",
	"YCbCr 4:2:2",
};
#else
UINT8 *format_setting[] = 
{
	"RGB",
	"YCbCr 4:4:4",
	"YCbCr 4:2:2",
};
#endif
#define HDMI_FMT_ITEM_NUM  (sizeof(format_setting)/sizeof(format_setting[0]))

UINT8 *audio_setting[] = 
{
    "BS Out",
    "LPCM Out",
//    "Auto",
};
#define HDMI_AUD_ITEM_NUM  (sizeof(audio_setting)/sizeof(audio_setting[0]))


#define TV_RATIO_NCNT	(sizeof(tv_ratio) / sizeof(tv_ratio[0]))
char* tv_ratio[] = 
{
	"Auto",
	"4:3PS",
	"4:3LB",
	"16:9",
};

#ifndef HDTV_SUPPORT
UINT16 video_output_ids[] = 
{
	RS_SYSTEM_TV_VIDEO_OUTPUT_CVBS,
	RS_SYSTEM_TV_VIDEO_OUTPUT_RGB,
	RS_SYSTEM_TV_VIDEO_OUTPUT_CVBS_YC
};
#define VIDEOOUT_NCNT	(sizeof(video_output_ids) / sizeof(video_output_ids[0]));

#else

#ifdef _S3281_
static char *video_output[] =
{
#if 1
    "CVBS",
#else
	"RGB",
#endif
};

#else

static char *video_output[] =
{
#ifdef CI_PLUS_SUPPORT
	"CVBS",	
#else
	"YUV",		
#endif
	"RGB",
};

#endif
#define VIDEOOUT_NCNT	(sizeof(video_output) / sizeof(video_output[0]));

#endif

UINT16 video_vcr_loopthrough_ids[] = 
{
	RS_VCRMASTER,
	RS_RECEIVERMASTER
};


#define RF_MODE_NCNT	(sizeof(rf_mode_stings) / sizeof(rf_mode_stings[0]));
char* rf_mode_stings[] = 
{
    "NTSC",
    "PAL-BG",
    "PAL-I",
    "PAL-DK",
};

UINT32 rf_ch_range[][3] =
{
    {14,83,1},
    {21,69,1},
    {21,69,1},
    {21,69,1},
};

#ifdef HDMI_DEEP_COLOR
UINT8 *deepcolor_setting[] = 
{
    "HDMI deepcolor 24",
    "HDMI deepcolor 30",
    "HDMI deepcolor 36",
    //"HDMI deepcolor 48",    
};
#define DEEP_COLOR_NCNT	(sizeof(deepcolor_setting) / sizeof(deepcolor_setting[0]));
#endif

void win_av_load_setting(void);
void win_av_set_vcrloop_action(BOOL update);
void win_av_init_items(void);
static void win_av_load_tv_mode_setting(BOOL bDraw);


void win_check_rf_channel(SYSTEM_DATA* p_sys_data);
UINT32 win_av_get_index(SYSTEM_DATA* p_sys_data);
void win_av_set_ratio(SYSTEM_DATA* p_sys_data,UINT16 result);
void win_av_enter_key(UINT8 id);


extern UINT8 set_tv_aspect_ratio_mode(UINT8 tv_ratio);
/*******************************************************************************
*	key mapping and event callback definition
*******************************************************************************/
#ifdef HDMI_DEEP_COLOR
void tvsys_check_hemi_deep_color(void)
{
    if(hdmi_is_deep_color_support())
    {
        OSD_SetAttr(&av_item_con10, C_ATTR_ACTIVE);
        OSD_SetAttr(&av_item_txtname10, C_ATTR_ACTIVE);
        OSD_SetAttr(&av_item_txtset10, C_ATTR_ACTIVE);
        OSD_SetAttr(&av_item_line10, C_ATTR_ACTIVE);     
    }
    else
    {          
        OSD_SetAttr(&av_item_con10, C_ATTR_INACTIVE);
        OSD_SetAttr(&av_item_txtname10, C_ATTR_INACTIVE);
        OSD_SetAttr(&av_item_txtset10, C_ATTR_INACTIVE);
        OSD_SetAttr(&av_item_line10, C_ATTR_INACTIVE);
        if(DEEPCOLOR_ID == win_av_con.FocusObjectID)
            win_av_con.FocusObjectID = TVMODE_ID; 
    }
    return;
}
void tvsys_update_hemi_deep_color_display(void)
{
    SYSTEM_DATA* sys_data;
    
    sys_data = sys_data_get();
    OSD_SetMultiselSel(av_item_set[DEEPCOLOR_ID - 1], sys_data->avset.deep_color);
    OSD_TrackObject( (POBJECT_HEAD)&win_av_con,C_DRAW_SIGN_EVN_FLG | C_UPDATE_ALL);
    return;
}
BOOL tvsys_check_edid_deep_color(UINT8 deep_color)
{
    BOOL ret = FALSE;
    UINT32 edid_res =0;
    enum EDID_DEEPCOLOR_CODE edid_deepcolor = EDID_DEEPCOLOR_24;

    edid_res = hdmi_is_deep_color_support();
    switch(deep_color)
    {
        case 0:
            //edid_deepcolor = EDID_DEEPCOLOR_24;
            return TRUE;
            break;
        case 1:
            edid_deepcolor = EDID_DEEPCOLOR_30;            
            break;
        case 2:
            edid_deepcolor = EDID_DEEPCOLOR_36;            
            break;
        default:
            return FALSE;
            break;
    }
    if(edid_res & edid_deepcolor)
        ret = TRUE;      
    else
        ret = FALSE;
    return ret;
}

#endif


#ifdef HDMI_CERTIFICATION_UI
BOOL check_hdmi_out_in_dvi_mode()
{
	UINT32 hdmi_mode;

	struct hdmi_device *hdmi_dev = (struct hdmi_device *)dev_get_by_type(NULL,HLD_DEV_TYPE_HDMI);	

	//return TRUE;	//Simulate DVI Mode

	if ((SUCCESS == hdmi_dev->io_control(hdmi_dev,HDMI_CMD_INTERFACE_MODE, (UINT32)&hdmi_mode, 0)) &&(hdmi_mode != TRUE)) // DVI Mode
	{
		return TRUE;
	}
	else
	{
		return FALSE;
	}
					
}

BOOL check_tv_display_in_hd_mode()
{

	SYSTEM_DATA* sys_data;

	sys_data = sys_data_get();

	if( 	(TV_MODE_720P_50 == sys_data->avset.tv_mode) || 
		(TV_MODE_720P_60 == sys_data->avset.tv_mode) || 
		(TV_MODE_1080I_25 == sys_data->avset.tv_mode) || 
		(TV_MODE_1080I_30 == sys_data->avset.tv_mode) || 
		(TV_MODE_1080P_24 == sys_data->avset.tv_mode) || 
		(TV_MODE_1080P_25== sys_data->avset.tv_mode) ||
		(TV_MODE_1080P_30== sys_data->avset.tv_mode) ||
		(TV_MODE_1080P_50== sys_data->avset.tv_mode) ||
		(TV_MODE_1080P_60== sys_data->avset.tv_mode)
		
	)
	{
		return TRUE;
	}
	else
	{
		return FALSE;
	}
					
}

DIGITAL_FMT_TYPE convert_ui_hdmi_out_sel_to_sys_video_format(UINT8 ui_hdmi_out_sel)
{

	DIGITAL_FMT_TYPE sys_video_fmt;

#ifdef HDMI_CERTIFICATION_UI

	switch(ui_hdmi_out_sel)
	{
		default:
		case 0:
			sys_video_fmt = SYS_DIGITAL_FMT_RGB;
			break;

		case 1:
			sys_video_fmt = SYS_DIGITAL_FMT_YCBCR_444;
			break;

		case 2:
			sys_video_fmt = SYS_DIGITAL_FMT_YCBCR_422;
			break;			
	}
#else
	sys_video_fmt = ui_hdmi_out_sel;
#endif	
	return sys_video_fmt;
}

enum HDMI_API_COLOR_SPACE convert_ui_hdmi_out_sel_to_sys_video_format_ext(UINT8 ui_hdmi_out_sel)
{
    enum HDMI_API_COLOR_SPACE sys_video_fmt;

    switch(ui_hdmi_out_sel)
    {
        default:
        case 0:
            sys_video_fmt = HDMI_RGB;
            break;
        case 1:
            sys_video_fmt = HDMI_YCBCR_444;
            break;
        case 2:
            sys_video_fmt = HDMI_YCBCR_422;
            break;
    }
	return sys_video_fmt;
}


UINT8 convert_sys_video_format_to_ui_hdmi_out_sel(DIGITAL_FMT_TYPE sys_video_fmt)
{

	UINT8 ui_hdmi_out_sel;


#ifdef HDMI_CERTIFICATION_UI
	switch(sys_video_fmt)
	{
		default :
		case SYS_DIGITAL_FMT_RGB:
			ui_hdmi_out_sel = 0;
			break;

		case SYS_DIGITAL_FMT_YCBCR_444:
			ui_hdmi_out_sel = 1;
			break;

		case SYS_DIGITAL_FMT_YCBCR_422:
			ui_hdmi_out_sel = 2;
			break;			
	}
#else
	ui_hdmi_out_sel = sys_video_fmt;
#endif

	return ui_hdmi_out_sel;
}
#endif

UINT8 convert_sys_video_format_to_ui_hdmi_out_sel_ext(enum HDMI_API_COLOR_SPACE sys_video_fmt)
{
    UINT8 ui_hdmi_out_sel = 0;
    
    switch(sys_video_fmt)
    {
        default:
        case HDMI_RGB:
            ui_hdmi_out_sel = 0;
            break;
        case HDMI_YCBCR_444:
            ui_hdmi_out_sel = 1;
            break;
        case HDMI_YCBCR_422:
            ui_hdmi_out_sel = 2;
            break;
    }
	return ui_hdmi_out_sel;
}

static VACTION av_item_sel_keymap(POBJECT_HEAD pObj, UINT32 key)
{
	VACTION act = VACT_PASS;

#if (defined GPIO_RGB_YUV_SWITCH)
    if (pObj->bID == VIDEOOUT_ID)
    {
        return VACT_PASS;
    }
#endif

    if (pObj->bID == VIDEOOUT_ID || pObj->bID == VCR_ID)
    {
	    if(api_Scart_VCR_Detect())
		    return VACT_PASS;
    }

	switch(key)
	{
	case V_KEY_LEFT:
		act = VACT_DECREASE;
		break;
	case V_KEY_RIGHT:
		act = VACT_INCREASE;
		break; 
	case V_KEY_ENTER:
		act = VACT_ENTER;
		break; 
	default:
		break;
	}

	return act;	
}

static PRESULT av_item_sel_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
	PRESULT ret = PROC_PASS;
	VACTION unact;
	UINT8 bID;
	UINT32 sel;
	UINT16* Uni_str;
	SYSTEM_DATA* sys_data;
	OSD_RECT rect;
	COM_POP_LIST_PARAM_T param;

#ifdef HDMI_CERTIFICATION_UI
	MULTISEL * msel;
#endif

	bID = OSD_GetObjID(pObj);
	sys_data = sys_data_get();
	switch(event)
	{
		case EVN_PRE_CHANGE:
			sel = *((UINT32*)param1);
			break;
			
		case EVN_POST_CHANGE:
			sel = param1;
			switch(bID)
			{
				case TVMODE_ID:
#if 1//ChengYu@20131108, pop up OK/NO dialog when change resolution
				{
					UINT8 back_saved;
					win_popup_choice_t choice;
					MULTISEL * msel;
					UINT8 pre_tvmode, new_tvmode;
					SYSTEM_DATA* p_sys_data;

					p_sys_data=sys_data_get();
					pre_tvmode = tvmode_setting_to_osd(p_sys_data->avset.tv_mode);

					new_tvmode = tvmode_setting_to_osd(tvmode_osd_to_setting(sel));

					/* If no change, no need to siwtch resolution */
					if (pre_tvmode != new_tvmode)
					{
						api_video_set_tvout(tvmode_osd_to_setting(sel));

						msel = av_item_set[TVMODE_ID - 1];
						OSD_SetMultiselCount(msel, get_tv_mode_count());
						OSD_SetMultiselSel(msel, new_tvmode);
						OSD_TrackObject((POBJECT_HEAD)av_items[TVMODE_ID - 1], C_UPDATE_ALL);

						win_compopup_init(WIN_POPUP_TYPE_OKNO);
						win_compopup_set_msg_ext(NULL,NULL, RS_POPUP_TVMODE_SAVE);
						win_compopup_set_default_choice(WIN_POP_CHOICE_NO);
						win_compopup_set_timer(1000, CTRL_MSG_TYPE_POPUP_TIMER, 15);

						choice = win_compopup_open_ext(&back_saved);
						if(choice != WIN_POP_CHOICE_YES)
						{
							/* Restore previous setting */
							api_video_set_tvout(tvmode_osd_to_setting(pre_tvmode));
							msel = av_item_set[TVMODE_ID - 1];
							OSD_SetMultiselCount(msel, get_tv_mode_count());
							OSD_SetMultiselSel(msel, pre_tvmode);
							OSD_TrackObject((POBJECT_HEAD)av_items[TVMODE_ID - 1], C_UPDATE_ALL);
						}
						else
						{
							/* TV MODE */
							p_sys_data->avset.tv_mode=tvmode_osd_to_setting(sel);
						}
					}
				}
#else
					sys_data->avset.tv_mode = tvmode_osd_to_setting(sel);
#ifdef ENABLE_ANTIFLICK
                                        if(sys_ic_get_chip_id() == ALI_S3811 ||sys_ic_get_chip_id() == ALI_S3602F || sys_ic_get_chip_id() == ALI_S3503)
                                        {
                                            if((SCART_YUV == sys_data->avset.scart_out)&&((sys_data->avset.tv_mode != TV_MODE_PAL)&&(sys_data->avset.tv_mode != TV_MODE_NTSC358)))
                                                OSDDrv_IoCtl((struct osd_device *)dev_get_by_id(HLD_DEV_TYPE_OSD,0), OSD_IO_DISABLE_ANTIFLICK, 0);
                                            else //if((sys_data->avset.tv_mode <= NTSC_443) && (FALSE == dis_info.bprogressive))
                                                OSDDrv_IoCtl((struct osd_device *)dev_get_by_id(HLD_DEV_TYPE_OSD,0), OSD_IO_ENABLE_ANTIFLICK, 1);
                                        }
#endif                     

					api_video_set_tvout(sys_data->avset.tv_mode);	
#ifdef HDMI_CERTIFICATION_UI
					msel = av_item_set[TVASPECT_ID - 1];
					if( check_tv_display_in_hd_mode() )
					{
						win_av_set_ratio(sys_data,3);	// 16:9
						sys_data_set_display_mode(&(sys_data->avset));

						OSD_SetMultiselCount(msel, 1);
						OSD_SetMultiselSel(msel, 3);
					}
					else
					{
						OSD_SetMultiselCount(msel, TV_RATIO_NCNT);
					}
					OSD_DrawObject((POBJECT_HEAD)msel, C_UPDATE_CONTENT);
					OSD_DrawObject((POBJECT_HEAD)&win_av_con, C_UPDATE_CONTENT);
#endif  					
#endif  					
					break;

				case TVASPECT_ID:
#ifdef HDMI_CERTIFICATION_UI					
					msel = av_item_set[TVASPECT_ID - 1];
					if( check_tv_display_in_hd_mode() )
					{	
						win_av_set_ratio(sys_data,3);	// 16:9
						OSD_SetMultiselSel(msel, 3);
					}
					else
#endif						
					{
						win_av_set_ratio(sys_data,sel);
					}
					sys_data_set_display_mode(&(sys_data->avset));			
					break;
					
				case VIDEOOUT_ID:
#ifdef HDTV_SUPPORT
#ifndef _S3281_
					if (sel == 0)
					{
						sys_data->avset.scart_out = SCART_YUV;
						#ifdef SD_PVR
							sys_data->avset.tv_mode = TV_MODE_PAL;
						#else
					    	sys_data->avset.tv_mode = TV_MODE_1080I_25;
						#endif
						//api_Scart_RGB_OnOff(0);
#ifdef ENABLE_ANTIFLICK
                        if(sys_ic_get_chip_id() == ALI_S3811 ||sys_ic_get_chip_id() == ALI_S3602F || sys_ic_get_chip_id() == ALI_S3503)
                        {
                            OSDDrv_IoCtl((struct osd_device *)dev_get_by_id(HLD_DEV_TYPE_OSD,0), OSD_IO_DISABLE_ANTIFLICK, 0);
                        }                        
 #endif
					}
					else
#endif
					{
						sys_data->avset.scart_out = SCART_RGB;
					    //api_Scart_RGB_OnOff(1);
#ifdef ENABLE_ANTIFLICK
                        if(sys_ic_get_chip_id() == ALI_S3811 ||sys_ic_get_chip_id() == ALI_S3602F || sys_ic_get_chip_id() == ALI_S3503)
                        {
                            OSDDrv_IoCtl((struct osd_device *)dev_get_by_id(HLD_DEV_TYPE_OSD,0), OSD_IO_ENABLE_ANTIFLICK, 1);
                        }                        
 #endif
					}
#ifndef GPIO_RGB_YUV_SWITCH
					api_video_set_tvout(sys_data->avset.tv_mode);
#endif
					win_av_load_tv_mode_setting(TRUE);
#else			
					sys_data->avset.scart_out = sel;
					if(sel == SCART_CVBS)
					{
						api_Scart_RGB_OnOff(0);
		                #ifdef VDAC_USE_SVIDEO_TYPE
						api_Svideo_OnOff(0);
		                #endif
					}
					else if(sel == SCART_RGB)
					{
						api_Scart_RGB_OnOff(1);
						//api_Svideo_OnOff(0);/*RGB output will cut off svideo output,ommit here*/
					}
					else
					{
						api_Scart_RGB_OnOff(0);
		                #ifdef VDAC_USE_SVIDEO_TYPE
						api_Svideo_OnOff(1);
		                #endif
					}
#endif
					win_av_set_vcrloop_action(TRUE);
					if(sys_data->avset.scart_out == SCART_RGB)
						api_Scart_OutPut_Switch(1);
					else
						api_Scart_OutPut_Switch(sys_data->vcrloopmode);
					break;
					
				case VCR_ID:
					sys_data->vcrloopmode = sel;
					api_Scart_OutPut_Switch(sys_data->vcrloopmode );
					break;
					
				case RFSYSTEM_ID:
					sys_data->avset.rf_mode = sel;
					win_check_rf_channel(sys_data);
					OSD_SetMultiselSelTable(av_item_set[RFCHAN_ID - 1], rf_ch_range[sel]);					
					sys_data_set_rf(sys_data->avset.rf_mode, sys_data->avset.rf_channel);
					break;
					
				case RFCHAN_ID:
					sys_data->avset.rf_channel = sel;
					sys_data_set_rf(sys_data->avset.rf_mode, sys_data->avset.rf_channel);
					break;
					
#ifdef HDTV_SUPPORT
				case HDMIOUT_ID:
#ifdef HDMI_CERTIFICATION_UI
					if(!check_hdmi_out_in_dvi_mode())
					{	
					    if(sys_ic_get_chip_id() < ALI_S3821)
					    {
                            // STB only output RGB in DVI mode
        					sys_data->avset.video_format = convert_ui_hdmi_out_sel_to_sys_video_format(sel);
        					sys_data_set_video_format(sys_data->avset.video_format);
    				    }
                        else
                        {   
                            sys_data->avset.video_format = convert_ui_hdmi_out_sel_to_sys_video_format_ext(sel);
                        #ifdef HDMI_DEEP_COLOR
                            if(2 == sel)
                            {
                                OSD_SetAttr(&av_item_con10, C_ATTR_INACTIVE);
                                OSD_SetAttr(&av_item_txtname10, C_ATTR_INACTIVE);
                                OSD_SetAttr(&av_item_txtset10, C_ATTR_INACTIVE);
                                OSD_SetAttr(&av_item_line10, C_ATTR_INACTIVE);                          
                                
                            }   
                            else
                            {
                                if(hdmi_is_deep_color_support())
                                {
                                    OSD_SetAttr(&av_item_con10, C_ATTR_ACTIVE);
                                    OSD_SetAttr(&av_item_txtname10, C_ATTR_ACTIVE);
                                    OSD_SetAttr(&av_item_txtset10, C_ATTR_ACTIVE);
                                    OSD_SetAttr(&av_item_line10, C_ATTR_ACTIVE);
                                }
                                                               
                            }
                            OSD_DrawObject((POBJECT_HEAD)&av_item_con10, C_DRAW_SIGN_EVN_FLG | C_UPDATE_ALL);
                        #endif
                            api_set_hdmi_color_space(sys_data->avset.video_format);
                            //sys_data_set_video_format(sys_data->avset.video_format);
                        }
                        
					}
#else
					sys_data->avset.video_format = sel;
					sys_data_set_video_format(sys_data->avset.video_format);
#endif
					break;
				case AUDIOOUT_ID:
					sys_data->avset.audio_output = sel;
					sys_data_set_audio_output(sys_data->avset.audio_output);
					break;
#endif
#if (SUPPORT_DUAL_OUTPUT_ONOFF)
				case DUALOUT_ID:
					sys_data->avset.dual_output = sel;
					sys_data_set_dual_output(sys_data->avset.dual_output);
					break;
#endif
#ifdef HDMI_DEEP_COLOR
                case DEEPCOLOR_ID:

                    if(tvsys_check_edid_deep_color(sel))
                    {
                        sys_data->avset.deep_color = sel;
                        sys_data_set_deep_color(sys_data->avset.deep_color);    
                    }
                    else
                    {
                        //the TV may not support
                        UINT8 back_saved;
                        OSD_SetMultiselSel(av_item_set[DEEPCOLOR_ID - 1], sys_data->avset.deep_color);
                        
                        win_compopup_init(WIN_POPUP_TYPE_OK);
                		win_compopup_set_msg("The HDMI TV not support this setting!", NULL, 0);
                		win_compopup_set_default_choice(WIN_POP_CHOICE_YES);
                		win_compopup_open_ext(&back_saved);
                        
                    }                    
                    break;
#endif                    
			} 		
			break;
			
		case EVN_REQUEST_STRING:
			sel = param1;
			Uni_str= (UINT16*)param2;
			switch(bID)
			{
				case TVMODE_ID:
					ComAscStr2Uni(get_tv_mode_string(sel), Uni_str);
					break;
					
				case TVASPECT_ID:
#ifdef HDMI_CERTIFICATION_UI
					if( check_tv_display_in_hd_mode() )					
					{
						sel = 3; // 16:9
					}
#endif					
					ComAscStr2Uni(tv_ratio[sel], Uni_str);
					break;
#ifdef HDTV_SUPPORT
				case VIDEOOUT_ID:
					ComAscStr2Uni(video_output[sel], Uni_str);
					break;
#endif
		//		case VCR_ID:			break;
				case RFSYSTEM_ID:
					ComAscStr2Uni(rf_mode_stings[sel], Uni_str);
					break;
		//		case RFCHAN_ID:			break;		
#ifdef HDMI_DEEP_COLOR
                case DEEPCOLOR_ID :
					ComAscStr2Uni(deepcolor_setting[sel], Uni_str);
                    break;
#endif                    
			}
			break;
		
		case EVN_UNKNOWN_ACTION:
			win_av_enter_key(bID);		
			break;
	}
 	return ret;
}

static VACTION av_item_con_keymap(POBJECT_HEAD pObj, UINT32 key)
{
	return VACT_PASS;
}

static PRESULT av_item_con_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
	return PROC_PASS;
}

static VACTION av_con_keymap(POBJECT_HEAD pObj, UINT32 key)
{
	VACTION act;
	
	switch(key)
	{
		case V_KEY_UP:
			act = VACT_CURSOR_UP;
			break;
		
		case V_KEY_DOWN:
			act = VACT_CURSOR_DOWN;
			break;
		
		case V_KEY_EXIT:
		case V_KEY_MENU:
			act = VACT_CLOSE;
			break;
		
		default:	
			act = VACT_PASS;
			break;
	}

	return act;
}

static PRESULT av_con_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
	PRESULT ret = PROC_PASS;
	VACTION unact;

	switch(event)
	{
		case EVN_PRE_OPEN:
			wincom_open_title((POBJECT_HEAD)&win_av_con,RS_SYSTEM_TV_SYSTEM, 0);
			win_av_load_setting();
			win_av_set_vcrloop_action(FALSE);
			win_av_init_items();

#ifdef SCART_RGB_UNSUPPORT
			remove_menu_item(&win_av_con, (OBJECT_HEAD *)&av_item_con3, CON_H + CON_GAP);
#endif

#ifdef HDMI_CERTIFICATION_UI
			remove_menu_item(&win_av_con, (OBJECT_HEAD *)&av_item_con3, CON_H + CON_GAP);
			remove_menu_item(&win_av_con, (OBJECT_HEAD *)&av_item_con5, CON_H + CON_GAP);
			remove_menu_item(&win_av_con, (OBJECT_HEAD *)&av_item_con6, CON_H + CON_GAP);
#else
#ifdef NEW_DEMO_FRAME
			remove_menu_item(&win_av_con, (OBJECT_HEAD *)&av_item_con5, CON_H + CON_GAP);
			remove_menu_item(&win_av_con, (OBJECT_HEAD *)&av_item_con6, CON_H + CON_GAP);
			remove_menu_item(&win_av_con, (OBJECT_HEAD *)&av_item_con7, CON_H + CON_GAP);
#endif
#endif
			break;

		case EVN_PRE_CLOSE:
			sys_data_save(1);
			/* Make OSD not flickering */
			*((UINT32*)param2) &= ~C_CLOSE_CLRBACK_FLG;	
			break;
		
		case EVN_MSG_GOT:
			if(param1 ==  CTRL_MSG_SUBTYPE_CMD_TVSAT_SWITCH)
			{
				win_av_load_tv_mode_setting(TRUE);
				ret = PROC_LOOP;
			}
#ifdef HDMI_DEEP_COLOR            
            else if(param1 == CTRL_MSG_SUBTYPE_CMD_HDMI_DEEP_COLOR_UPDATE)
            {      
                win_av_load_setting();
                tvsys_update_hemi_deep_color_display();
            }
#endif            
			break;
		
		default:
			break;
	}

	return ret;	
}


/*******************************************************************************
*	other functions  definition
*******************************************************************************/
UINT32 get_tv_mode_count(void)
{
	if (sys_data_get_scart_out() == SCART_RGB)
	{
		return TV_MODE_SD_NCNT;
	}

#ifdef HDMI_TV_TEST // for hdmi tv test, open all resolution
#ifdef HDMI_CERTIFICATION_UI
	if(check_hdmi_out_in_dvi_mode())
	{
		return TV_MODE_DVI_NCNT;
	}
	else
#endif	
#endif
	{
		return TV_MODE_NCNT;
	}
}

UINT32 get_tv_mode_set(UINT32 index)
{
	if (sys_data_get_scart_out() == SCART_RGB)
	{
		return tv_mode_set_sd[index];
	}

#ifdef HDMI_TV_TEST // for hdmi tv test, open all resolution
#ifdef HDMI_CERTIFICATION_UI
	if(check_hdmi_out_in_dvi_mode())
	{
		return tv_mode_set_for_dvi[index];
	}
	else
#endif	
#endif
	{
		return tv_mode_set[index];
	}
}
//**************************//
UINT32 get_tv_mode_set_pal(UINT32 index)
{
 return tv_mode_pal[index];
}

UINT32 get_tv_mode_set_ntsc(UINT32 index)
{
 return tv_mode_ntsc[index];
}

UINT32 get_tv_mode_set_pal_ntsc(UINT32 index)
{
 return tv_mode_pal_ntsc[index];
}
//********************************//
char *get_tv_mode_string(UINT32 index)
{
	if (sys_data_get_scart_out() == SCART_RGB)
	{
		return tv_mode_sd[index];
	}

#ifdef HDMI_TV_TEST // for hdmi tv test, open all resolution
#ifdef HDMI_CERTIFICATION_UI
	if(check_hdmi_out_in_dvi_mode())
	{
		return tv_mode_for_dvi[index];
	}
	else
#endif
#endif
{
		return tv_mode[index];
	}
}

UINT32 get_tv_mode_panel_next(UINT32 index)
{
	UINT32 tv_mode;

	// panel not resopnse by source or by Native tv.
	do
	{
		index = (index+1)%get_tv_mode_count();

		tv_mode = get_tv_mode_set(index);
		if(tv_mode !=TV_MODE_AUTO && tv_mode != TV_MODE_BY_EDID)
		{
			break;
		}
	}while(1);	
	
	return index;
}

//***********************//

UINT32 pal_ntsc_tvmode_setting_to_osd(enum TV_SYS_TYPE set)
{
	UINT32 i;
	UINT32 n = TV_MODE_COUNT;
#ifdef SD_PVR
	for (i = 0; i < n; i++)
	{
		if (set == get_tv_mode_set_pal(i))
			{
			i=5;
			break;
			}
			else if (set == get_tv_mode_set_ntsc(i))
			{
			i=3;
			break;
			}
		
	}
#else
	for (i = 0; i < n; i++)
	{
		if (set == get_tv_mode_set_pal_ntsc(i))
			
			break;
	
	}
#endif
	
	return i;
}

//*************************/
UINT32 tvmode_setting_to_osd(enum TV_SYS_TYPE set)
{
	UINT32 i;
	UINT32 n = get_tv_mode_count();
    
	for (i = 0; i < n; i++)
	{
		if (set == get_tv_mode_set(i))
			break;
	}
	if(i == n)
		i = 0;

	return i;
}

UINT32 tvmode_osd_to_setting(UINT32 osd)
{
   	if (osd >= get_tv_mode_count())
   	{
   		osd = 0;
   	}

   	return get_tv_mode_set(osd);
}

void win_av_init_items(void)
{
    static BOOL init = FALSE;
    UINT32 vcr_loop_item_flag;
    UINT32 rf_item_flag;
    POBJECT_HEAD first_item;
    CONTAINER* root = &win_av_con;
    

	if(!init)
	{
		vcr_loop_item_flag = 0;
		rf_item_flag = 1;

		if(!vcr_loop_item_flag)
		{
			remove_menu_item(root,(POBJECT_HEAD)av_items[VCR_ID - 1],CON_H + CON_GAP);
		}
		if(!rf_item_flag)
		{
			remove_menu_item(root,(POBJECT_HEAD)av_items[RFSYSTEM_ID - 1],CON_H + CON_GAP);
			remove_menu_item(root,(POBJECT_HEAD)av_items[RFCHAN_ID - 1],CON_H + CON_GAP);
		}
#ifdef _S3281_
        remove_menu_item(root, (POBJECT_HEAD)av_items[VIDEOOUT_ID-1], CON_H + CON_GAP);
#ifdef HDTV_SUPPORT
        remove_menu_item(root, (POBJECT_HEAD)av_items[AUDIOOUT_ID-1], CON_H + CON_GAP);
#endif
#endif

		init = TRUE;
	}
}

static void win_av_load_tv_mode_setting(BOOL bDraw)
{
	MULTISEL * msel;	
	SYSTEM_DATA* sys_data;
	UINT32 i,sel,cnt;
	UINT32 focus = OSD_GetFocusID((POBJECT_HEAD)&win_av_con);

	sys_data = sys_data_get();

	/* TV MODE */
	msel = av_item_set[TVMODE_ID - 1];
	OSD_SetMultiselCount(msel, get_tv_mode_count());

	sel = tvmode_setting_to_osd(sys_data->avset.tv_mode);
	OSD_SetMultiselSel(msel, sel);
	if (bDraw)
	{
		if (focus == TVMODE_ID)
		{
			OSD_TrackObject((POBJECT_HEAD)av_items[TVMODE_ID - 1], C_UPDATE_ALL);
		}
		else
		{
			OSD_DrawObject((POBJECT_HEAD)av_items[TVMODE_ID - 1], C_UPDATE_ALL);
		}
	}

	/* Video Output */
	msel = av_item_set[VIDEOOUT_ID - 1];
#ifdef HDTV_SUPPORT
#ifdef _S3281_
    if (sys_data_get_scart_out() == SCART_RGB)
        sel = 0;
    else
        sel = 0;
#else
	if (sys_data_get_scart_out() == SCART_YUV)
	{
		sel = 0;
	}
	else
	{
		sel = 1;
	}
#endif
#else			
	sel = sys_data->avset.scart_out;
#endif
	OSD_SetMultiselSel(msel, sel);
	if (bDraw)
	{
		if (focus == VIDEOOUT_ID)
		{
			OSD_TrackObject((POBJECT_HEAD)av_items[VIDEOOUT_ID - 1], C_UPDATE_ALL);
		}
		else
		{
			OSD_DrawObject((POBJECT_HEAD)av_items[VIDEOOUT_ID - 1], C_UPDATE_ALL);
		}
	}
}

void win_av_load_setting(void)
{
	MULTISEL * msel;	
	SYSTEM_DATA* sys_data;
	UINT32 i,sel,cnt,rf_mode;
	
	sys_data = sys_data_get();
	

	/* TV MODE */
	msel = av_item_set[TVMODE_ID - 1];
	OSD_SetMultiselCount(msel, get_tv_mode_count());

	sel = tvmode_setting_to_osd(sys_data->avset.tv_mode);
	OSD_SetMultiselSel(msel, sel);

	/* TV Aspect */
	msel = av_item_set[TVASPECT_ID - 1];
	sel = win_av_get_index(sys_data);
	OSD_SetMultiselSel(msel, sel);

#ifdef HDMI_CERTIFICATION_UI
	if( check_tv_display_in_hd_mode() )
	{
		OSD_SetMultiselCount(msel, 1);
		OSD_SetMultiselSel(msel, 3);		// 16:9
	}
	else
	{
		OSD_SetMultiselCount(msel, TV_RATIO_NCNT);
	}	
#endif

	/* Video Output */
	msel = av_item_set[VIDEOOUT_ID - 1];
#ifdef HDTV_SUPPORT
#ifdef _S3281_
	if (sys_data_get_scart_out() == SCART_RGB)
		sel = 0;
    else
        sel = 0;
#else    
	if (sys_data_get_scart_out() == SCART_YUV)
		sel = 0;
	else
		sel = 1;
#endif
#else			
	sel = sys_data->avset.scart_out;
#endif
	OSD_SetMultiselSel(msel, sel);

	/* VCR loopthrough */
	msel = av_item_set[VCR_ID - 1];
	if(sys_data->avset.scart_out == SCART_RGB)
		sel = 1;
	else
		sel = sys_data->vcrloopmode;
	OSD_SetMultiselSel(msel, sel);
	
	/* RF Mode */
	msel = av_item_set[RFSYSTEM_ID - 1];
	cnt = OSD_GetMultiselCount(msel);
	sel = sys_data->avset.rf_mode;
	if(sel >= cnt)
	{
		sel = 0;
		sys_data->avset.rf_mode = sel;
	}
	OSD_SetMultiselSel(msel, sel);
	rf_mode = sel;

	/* RF Channel */
	msel = av_item_set[RFCHAN_ID - 1];
	sel = sys_data->avset.rf_channel;
	if(sel < rf_ch_range[rf_mode][0] || sel> rf_ch_range[rf_mode][1])
	{
		sel =  rf_ch_range[rf_mode][0];
		sys_data->avset.rf_channel = sel;
		sys_data_set_rf(sys_data->avset.rf_mode,sys_data->avset.rf_channel);
	}
	OSD_SetMultiselSel(msel, sel);
	OSD_SetMultiselSelTable(msel, rf_ch_range[rf_mode]);

#ifdef HDMI_DEEP_COLOR
    tvsys_check_hemi_deep_color();
#endif

#ifdef HDTV_SUPPORT
	/* HDMI Video Out */
	msel = av_item_set[HDMIOUT_ID - 1];

#ifdef HDMI_CERTIFICATION_UI
	if( check_hdmi_out_in_dvi_mode() )
	{
		sel = 0;	//RGB Mode
		OSD_SetMultiselCount(msel, 1);
	}
	else
	{
	    if(sys_ic_get_chip_id()< ALI_S3821)
        {
	        sel = convert_sys_video_format_to_ui_hdmi_out_sel(sys_data->avset.video_format);
        	OSD_SetMultiselCount(msel, HDMI_FMT_ITEM_NUM);
        }
        else
        {
            sel = convert_sys_video_format_to_ui_hdmi_out_sel_ext(sys_data->avset.video_format);
            OSD_SetMultiselCount(msel, HDMI_FMT_ITEM_NUM);
#ifdef HDMI_DEEP_COLOR
            if(2 == sel)
            {
                OSD_SetAttr(&av_item_con10, C_ATTR_INACTIVE);
                OSD_SetAttr(&av_item_txtname10, C_ATTR_INACTIVE);
                OSD_SetAttr(&av_item_txtset10, C_ATTR_INACTIVE);
                OSD_SetAttr(&av_item_line10, C_ATTR_INACTIVE);
            }
#endif            
        }
	}
#else
	sel = sys_data->avset.video_format;
#endif

	OSD_SetMultiselSel(msel, sel);

	/* Digital Audio Out */
	msel = av_item_set[AUDIOOUT_ID - 1];

	sel = sys_data->avset.audio_output;
	OSD_SetMultiselSel(msel, sel);
#endif

#if (SUPPORT_DUAL_OUTPUT_ONOFF)
	/* Dual Output */
	msel = av_item_set[DUALOUT_ID- 1];

	sel = sys_data->avset.dual_output;
	OSD_SetMultiselSel(msel, sel);
#endif

#ifdef HDMI_DEEP_COLOR
    msel = av_item_set[DEEPCOLOR_ID - 1];

    sel = sys_data->avset.deep_color;
    OSD_SetMultiselSel(msel, sel);
    
#endif

}

void win_av_set_vcrloop_action(BOOL update)
{
	POBJECT_HEAD pObj;
	UINT8 action;
	SYSTEM_DATA* sys_data;

	/* Check VCR Loopthroup item exist or not*/
	pObj = OSD_GetContainerNextObj(&win_av_con);
	while(pObj != NULL && pObj != (POBJECT_HEAD)av_items[VCR_ID - 1] )
		pObj = OSD_GetObjpNext(pObj);
	if(pObj == NULL)
		return;

	sys_data = sys_data_get();
	if(sys_data->avset.scart_out == SCART_RGB)
		action = C_ATTR_INACTIVE;
	else
		action = C_ATTR_ACTIVE;

	if( ! OSD_CheckAttr(av_items[VCR_ID - 1], action))
	{
		if(action == C_ATTR_INACTIVE)
			OSD_SetMultiselSel(av_item_set[VCR_ID - 1], 1);
		else
			OSD_SetMultiselSel(av_item_set[VCR_ID - 1], sys_data->vcrloopmode);
		OSD_SetAttr(av_items[VCR_ID - 1], action);
		pObj = OSD_GetContainerNextObj(av_items[VCR_ID - 1]);
		while(pObj)
		{
			OSD_SetAttr(pObj , action);
			pObj = OSD_GetObjpNext(pObj);				
		}
		if(update)
			OSD_DrawObject( (POBJECT_HEAD)av_items[VCR_ID - 1],C_DRAW_SIGN_EVN_FLG | C_UPDATE_ALL);
	}
}

void win_check_rf_channel(SYSTEM_DATA* p_sys_data)
{
	if((p_sys_data->avset.rf_channel>rf_ch_range[p_sys_data->avset.rf_mode][1])||(p_sys_data->avset.rf_channel<rf_ch_range[p_sys_data->avset.rf_mode][0]))
	{
		p_sys_data->avset.rf_channel=rf_ch_range[p_sys_data->avset.rf_mode][0];
		OSD_SetMultiselSel(av_item_set[RFCHAN_ID - 1], p_sys_data->avset.rf_channel);
		OSD_DrawObject((POBJECT_HEAD)av_items[RFCHAN_ID - 1], C_DRAW_SIGN_EVN_FLG | C_UPDATE_ALL);
	}
}

UINT32 win_av_get_index(SYSTEM_DATA* p_sys_data)
{
	if(p_sys_data->avset.tv_ratio==TV_ASPECT_RATIO_169)
	{
		return 3;
	}
	else if(p_sys_data->avset.tv_ratio==TV_ASPECT_RATIO_AUTO)
	{
		return 0;
	}
	else
	{
		if(p_sys_data->avset.display_mode==DISPLAY_MODE_PANSCAN)
		{
			return 1;
		}
		else
		{
			return 2;
		}
	}
}

void win_av_set_ratio(SYSTEM_DATA* p_sys_data,UINT16 result)
{
	if(result == 0)
	{
		p_sys_data->avset.tv_ratio = TV_ASPECT_RATIO_AUTO;
		p_sys_data->avset.display_mode = DISPLAY_MODE_PANSCAN;
	}
	else if(result == 1)
	{
		p_sys_data->avset.tv_ratio = TV_ASPECT_RATIO_43;
		p_sys_data->avset.display_mode = DISPLAY_MODE_PANSCAN;
	}
	else if(result==2)
	{
		p_sys_data->avset.tv_ratio = TV_ASPECT_RATIO_43;
		p_sys_data->avset.display_mode = DISPLAY_MODE_LETTERBOX;
	}
	else
	{
		p_sys_data->avset.tv_ratio = TV_ASPECT_RATIO_169;
		p_sys_data->avset.display_mode = DISPLAY_MODE_LETTERBOX;
	}
    if( (TV_ASPECT_RATIO_43 == p_sys_data->avset.tv_ratio)
       ||(TV_ASPECT_RATIO_169 == p_sys_data->avset.tv_ratio) )
    {
        set_tv_aspect_ratio_mode(p_sys_data->avset.tv_ratio - 1);
    }
}

UINT8 win_language_get_tvsys_num()
{
	UINT8 ID=OSD_GetFocusID((POBJECT_HEAD)&win_av_con);
	SYSTEM_DATA* p_sys_data=sys_data_get();
	UINT8 num=0;
	
	switch(ID)
	{
		case TVMODE_ID:
			num=get_tv_mode_count();
			break;
		case TVASPECT_ID:

#ifdef HDMI_CERTIFICATION_UI
			if( check_tv_display_in_hd_mode() )
			{
				num= 1;	//16:9 Mode only
			}
			else
#endif
			{
				num=TV_RATIO_NCNT;
			}
			break;
		case VIDEOOUT_ID:
			num = VIDEOOUT_NCNT;
			break;
		case RFSYSTEM_ID:
			num=RF_MODE_NCNT;
			break;
		case RFCHAN_ID:
			num=rf_ch_range[p_sys_data->avset.rf_mode][1]-rf_ch_range[p_sys_data->avset.rf_mode][0]+1;
			break;
#ifdef HDTV_SUPPORT
		case HDMIOUT_ID:
#ifdef HDMI_CERTIFICATION_UI
			if( check_hdmi_out_in_dvi_mode() )
			{
				num= 1;	// RGB out only
			}
			else
#endif
			{
				num=HDMI_FMT_ITEM_NUM;
			}
			break;
		case AUDIOOUT_ID:
			num=HDMI_AUD_ITEM_NUM;
			break;
#endif
#ifdef HDMI_DEEP_COLOR
        case DEEPCOLOR_ID :
            num = DEEP_COLOR_NCNT;
			break;
#endif
	}
	return num;
}

PRESULT comlist_tvsys_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
	UINT16 i,wTop;
	UINT8 id;
	char str_len;
	OBJLIST* ol;
	UINT8 temp[4];
	SYSTEM_DATA* p_sys_data=sys_data_get();
	
	PRESULT cbRet = PROC_PASS;

	ol = (OBJLIST*)pObj;
	
	if(event==EVN_PRE_DRAW)
	{
		id=OSD_GetFocusID((POBJECT_HEAD)&win_av_con);
		switch(id)
		{
			case TVMODE_ID:
			    	wTop = OSD_GetObjListTop(ol);
			    	for(i=0;i<ol->wDep && (i+wTop)<ol->wCount;i++)
			    	{
						win_comlist_set_str(i + wTop,get_tv_mode_string(i+wTop),NULL,0);
			    	}
				break;
			
			case TVASPECT_ID:
#ifdef HDMI_CERTIFICATION_UI
				if( check_tv_display_in_hd_mode() )
				{
					OSD_SetObjListCount(ol, 1);
					//insert [16:9] into com_list[0];
					win_comlist_set_str(0, tv_ratio[3], NULL,0);
					break;
				}
				else
				{
					wTop = OSD_GetObjListTop(ol);
					OSD_SetObjListCount(ol, TV_RATIO_NCNT);
				}
#else
				wTop = OSD_GetObjListTop(ol);
#endif
			    	for(i=0;i<ol->wDep && (i+wTop)<ol->wCount;i++)
			    	{
						win_comlist_set_str(i + wTop,tv_ratio[i+wTop],NULL,0);
			    	}
				break;

				
			case VIDEOOUT_ID:
			    	wTop = OSD_GetObjListTop(ol);
			    	for(i=0;i<ol->wDep && (i+wTop)<ol->wCount;i++)
			    	{
#ifndef HDTV_SUPPORT
						win_comlist_set_str(i + wTop,NULL,NULL,video_output_ids[i]);
#else
						win_comlist_set_str(i + wTop,video_output[i+wTop],NULL,0);
#endif
			    	}			
				break;
				
			case RFSYSTEM_ID:
			    	wTop = OSD_GetObjListTop(ol);
			    	for(i=0;i<ol->wDep && (i+wTop)<ol->wCount;i++)
			    	{
						win_comlist_set_str(i + wTop,rf_mode_stings[i+wTop],NULL,0);
			    	}
				break;
				
			case RFCHAN_ID:
			    	wTop = OSD_GetObjListTop(ol);
			    	for(i=0;i<ol->wDep && (i+wTop)<ol->wCount;i++)
			    	{
						sprintf(temp,"%d", i+wTop+rf_ch_range[p_sys_data->avset.rf_mode][0]);
						win_comlist_set_str(i + wTop,temp,NULL,0);
			    	}
				break;

			
#ifdef HDTV_SUPPORT
			case HDMIOUT_ID:
			    	wTop = OSD_GetObjListTop(ol);
			    	for(i=0;i<ol->wDep && (i+wTop)<ol->wCount;i++)
			    	{
						win_comlist_set_str(i + wTop,format_setting[i+wTop],NULL,0);
			    	}
				break;
				
			case AUDIOOUT_ID:
			    	wTop = OSD_GetObjListTop(ol);
			    	for(i=0;i<ol->wDep && (i+wTop)<ol->wCount;i++)
			    	{
						win_comlist_set_str(i + wTop,audio_setting[i+wTop],NULL,0);
			    	}
				break;
#endif
#ifdef HDMI_DEEP_COLOR
            case DEEPCOLOR_ID :
			    	wTop = OSD_GetObjListTop(ol);
                    for(i = 0; i<ol->wDep && (i+wTop)<ol->wCount;i++)
                    {
						win_comlist_set_str(i + wTop,deepcolor_setting[i+wTop],NULL,0);
                    }
#endif
		}
	}
	else if(event == EVN_POST_CHANGE)
	{
		cbRet = PROC_LEAVE;
	}

	return cbRet;
}



void win_av_enter_key(UINT8 id)
{
	SYSTEM_DATA* p_sys_data=sys_data_get();
	UINT16 result;
	OSD_RECT rect;
	COM_POP_LIST_PARAM_T param;
	UINT16 sel;
	POBJECT_HEAD pObj,pObjItem;
	MULTISEL* msel;
	

	msel = av_item_set[id - 1];
	pObj = (POBJECT_HEAD)msel;
	pObjItem = (POBJECT_HEAD)av_items[id - 1];
	
#if Maker_GUI_ON
	rect.uTop=Maker_GUI_SM_T;
	rect.uLeft=Maker_GUI_MM_L+(Maker_GUI_SM_W/2);
	rect.uHeight=300;
	rect.uWidth=(Maker_GUI_SM_W/2);
#else
	rect.uLeft=CON_L+SEL_L_OF;
	rect.uWidth=SEL_W;
	rect.uTop = pObj->frame.uTop;
#endif	

	param.selecttype = POP_LIST_SINGLESELECT;

	extern UINT8 g_rgb_yuv_changed;

	switch(id)
	{
		case TVMODE_ID:
#if Maker_GUI_ON
#else
			rect.uHeight=300;
#endif			
			param.cur = tvmode_setting_to_osd(p_sys_data->avset.tv_mode);
			sel  = win_com_open_sub_list(POP_LIST_MENU_TVSYS,&rect,&param);
			if (sel == param.cur)
			{
				break;
			}
#ifdef GPIO_RGB_YUV_SWITCH
			if (g_rgb_yuv_changed)
			{
				break;
			}
#endif
			OSD_SetMultiselSel(msel, sel);
			OSD_NotifyEvent(pObj,EVN_POST_CHANGE,(UINT32)sel, 0);
			OSD_TrackObject(pObjItem,C_DRAW_SIGN_EVN_FLG | C_UPDATE_ALL);
			break;
		
		case TVASPECT_ID:
#if Maker_GUI_ON
#else
			rect.uHeight= 300;//26*4+20;
#endif			
			param.cur=win_av_get_index(p_sys_data);
			sel = win_com_open_sub_list(POP_LIST_MENU_TVSYS,&rect,&param);

#ifdef HDMI_CERTIFICATION_UI		
			if( check_tv_display_in_hd_mode())
			{
				// only [16:9 mode] in com_list, therefore don't need to change the tv mode 			
				sel = 3;	// 16:9
			}
#endif

			if (sel == param.cur)
			{
				break;
			}
#ifdef GPIO_RGB_YUV_SWITCH
			if (g_rgb_yuv_changed)
			{
				break;
			}
#endif

			OSD_SetMultiselSel(msel, sel);
			OSD_NotifyEvent(pObj,EVN_POST_CHANGE,(UINT32)sel, 0);
			OSD_TrackObject(pObjItem,C_DRAW_SIGN_EVN_FLG | C_UPDATE_ALL);

			break;
		
		case VIDEOOUT_ID:
#ifdef GPIO_RGB_YUV_SWITCH
			if (g_rgb_yuv_changed)
			{
				break;
			}
#endif
			#ifndef SD_UI
#if Maker_GUI_ON
#else			
			rect.uHeight= 300;//26*4+20;
#endif			
			#else
			rect.uHeight= 200;//26*4+20;
			#endif
#ifdef HDTV_SUPPORT
			if (sys_data_get_scart_out() == SCART_YUV)
			{
				param.cur = 0;
			}
			else
			{
				param.cur = 1;
			}
#else			
			param.cur = p_sys_data->avset.scart_out;
#endif

			sel = win_com_open_sub_list(POP_LIST_MENU_TVSYS,&rect,&param);
			if (sel == param.cur)
			{
				break;
			}

			OSD_SetMultiselSel(msel, sel);
			OSD_NotifyEvent(pObj,EVN_POST_CHANGE,(UINT32)sel, 0);
			OSD_TrackObject(pObjItem,C_DRAW_SIGN_EVN_FLG | C_UPDATE_ALL);
			break;
		
		case RFSYSTEM_ID:
#if Maker_GUI_ON
#else		
			rect.uTop = 240;
			rect.uHeight= 300;//26*4+20;
#endif			
			param.cur = p_sys_data->avset.rf_mode;
			sel = win_com_open_sub_list(POP_LIST_MENU_TVSYS,&rect,&param);
			if (sel == param.cur)
			{
				break;
			}
#ifdef GPIO_RGB_YUV_SWITCH
			if (g_rgb_yuv_changed)
			{
				break;
			}
#endif

			OSD_SetMultiselSel(msel, sel);
			OSD_NotifyEvent(pObj,EVN_POST_CHANGE,(UINT32)sel, 0);
			OSD_TrackObject(pObjItem,C_DRAW_SIGN_EVN_FLG | C_UPDATE_ALL);
			break;
		
		case RFCHAN_ID:
#if Maker_GUI_ON
#else		
			rect.uTop = 240;
			rect.uHeight = 300;//150;
#endif			
			param.cur=p_sys_data->avset.rf_channel-rf_ch_range[p_sys_data->avset.rf_mode][0];
			sel = win_com_open_sub_list(POP_LIST_MENU_TVSYS,&rect,&param)+rf_ch_range[p_sys_data->avset.rf_mode][0];
			if (sel == param.cur)
			{
				break;
			}
#ifdef GPIO_RGB_YUV_SWITCH
			if (g_rgb_yuv_changed)
			{
				break;
			}
#endif

			OSD_SetMultiselSel(msel, sel);
			OSD_NotifyEvent(pObj,EVN_POST_CHANGE,(UINT32)sel, 0);		
			OSD_TrackObject(pObjItem,C_DRAW_SIGN_EVN_FLG | C_UPDATE_ALL);
			break;
		
#ifdef HDTV_SUPPORT
		case HDMIOUT_ID:
#if Maker_GUI_ON
#else		
			rect.uTop = 240;
			rect.uHeight = 300;//26*5+20;
#endif			
#ifdef HDMI_CERTIFICATION_UI
            if(sys_ic_get_chip_id() < ALI_S3821)
            {
        		param.cur = convert_sys_video_format_to_ui_hdmi_out_sel(p_sys_data->avset.video_format);
            }
            else
            {
        		param.cur = convert_sys_video_format_to_ui_hdmi_out_sel_ext(p_sys_data->avset.video_format);
            }
#else
			param.cur = p_sys_data->avset.video_format;
#endif
			sel = win_com_open_sub_list(POP_LIST_MENU_TVSYS,&rect,&param);
			if (sel == param.cur)
			{
				break;
			}
#ifdef GPIO_RGB_YUV_SWITCH
			if (g_rgb_yuv_changed)
			{
				break;
			}
#endif

			OSD_SetMultiselSel(msel, sel);
			OSD_NotifyEvent(pObj,EVN_POST_CHANGE,(UINT32)sel, 0);
			OSD_TrackObject(pObjItem,C_DRAW_SIGN_EVN_FLG | C_UPDATE_ALL);
			break;
		
		case AUDIOOUT_ID:
			#ifndef SD_UI
#if Maker_GUI_ON
#else			
			rect.uTop = 240;
			rect.uHeight = 260;//26*3+20;
#endif			
			#else
			//rect.uTop = 240;
			rect.uHeight = 150;//26*3+20;
			#endif
			param.cur = p_sys_data->avset.audio_output;
			sel = win_com_open_sub_list(POP_LIST_MENU_TVSYS,&rect,&param);
			if (sel == param.cur)
			{
				break;
			}
#ifdef GPIO_RGB_YUV_SWITCH
			if (g_rgb_yuv_changed)
			{
				break;
			}
#endif

			OSD_SetMultiselSel(msel, sel);
			OSD_NotifyEvent(pObj,EVN_POST_CHANGE,(UINT32)sel, 0);
			OSD_TrackObject(pObjItem,C_DRAW_SIGN_EVN_FLG | C_UPDATE_ALL);
			break;
#endif
#ifdef HDMI_DEEP_COLOR
        case DEEPCOLOR_ID :
			#ifndef SD_UI
#if Maker_GUI_ON
#else
			rect.uTop = 240;
			rect.uHeight = 260;//26*3+20;
#endif			
			#else
			//rect.uTop = 240;
			rect.uHeight = 150;//26*3+20;
			#endif
            param.cur = p_sys_data->avset.deep_color;
            
            sel = win_com_open_sub_list(POP_LIST_MENU_TVSYS, &rect,&param);
            if(sel == param.cur)
            {
                break;
            }

            OSD_SetMultiselSel(msel, sel);
            OSD_NotifyEvent(pObj, EVN_POST_CHANGE, (UINT32)sel, 0);
			OSD_TrackObject(pObjItem,C_DRAW_SIGN_EVN_FLG | C_UPDATE_ALL);

#endif
	}
	
}
